package com.dduggs.note.arithmetic.number;

import java.math.BigDecimal;

public class NumberLengthCheck {

    public static void companyLengthValidator(String company, Double compareValue, int integerLength, int decimalLength, String description) {

        //转换后的精度
        BigDecimal bigDecimal = new BigDecimal(new BigDecimal(company).stripTrailingZeros().toString());

        if ((bigDecimal.intValue() + "").length() > integerLength) {

            System.out.println(description + "整数位过长");
        }
        //小数长度校验
        if (bigDecimal.scale() > decimalLength) {

            System.out.println(description + "小数位过长");
        }
        int aa=bigDecimal.compareTo(new BigDecimal(compareValue));
        if(bigDecimal.compareTo(new BigDecimal(compareValue))>0){
            System.out.println(description + "大小超出限制");
        }
    }

    public static void main(String[] args) {
        Double   test=1000000000.02;
        Double compareValue=100000000.00;
        companyLengthValidator(test.toString(),compareValue,9,2,"注册资金");

    }

}
